package com.xywl.escort.view.bandcard;

import com.xywl.escort.bean.BaseReq;
import com.xywl.escort.bean.FindBankBaseInfoListResp;
import com.xywl.escort.net.BaseSubscriber;
import com.xywl.escort.net.ExceptionHandle;
import com.xywl.escort.net.api.service.ApiServer;
import com.xywl.escort.utils.RxUtil;

import javax.inject.Inject;

/**
 * Created by 32422 on 2017/10/25.
 */

public class CooperativeBandPresenter implements CooperativeBandContract.Presenter {
    private CooperativeBandContract.View mView;
    private ApiServer mApiServer;

    @Inject
    CooperativeBandPresenter(ApiServer apiServer) {
        mApiServer = apiServer;
    }

    @Override
    public void subscribe() {

    }

    @Override
    public void unSubscribe() {
        mView = null;
    }

    @Override
    public void takeView(CooperativeBandContract.View view) {
        this.mView = view;
    }

    @Override
    public void findBankBaseInfoList() {
        BaseReq req = new BaseReq();
        mApiServer.findBankBaseInfoList(req)
                .compose(RxUtil.<FindBankBaseInfoListResp>applySchedulers(RxUtil.IO_ON_UI_TRANSFORMER_BACK_PRESSURE))
                .compose(mView.<FindBankBaseInfoListResp>bindToLife())
                .subscribe(new BaseSubscriber<FindBankBaseInfoListResp>() {
                    @Override
                    protected void hideDialog() {

                    }

                    @Override
                    protected void showDialog() {

                    }

                    @Override
                    public void onError(ExceptionHandle.ResponseThrowable e) {
                        mView.findBankBaseInfoListFailure();
                    }

                    @Override
                    public void onNext(FindBankBaseInfoListResp resp) {
                        if (null != resp && resp.isOk()) {
                            mView.findBankBaseInfoListSuccess(resp);
                        } else {
                            mView.findBankBaseInfoListFailure();
                        }
                    }
                });
    }
}
